using UnityEngine;
using System.Collections;

public class Platform : MonoBehaviour
{
    public PagePropertie currentPageProperties;
    private Square zone;

    public void Build( bool isOnTop )
    {
        GameObject avatar = new GameObject();
        zone = avatar.AddComponent<Square>();

        zone.transform.parent = this.transform;

        if (isOnTop)
        {
            topBuild();
        }
        else
        {
            bottomBuild();
        }

        zone.renderer.material = (Material)Resources.Load("PlatformMat");
    }

    public void topBuild()
    {
        zone.Build(new Vector3(0, -0.3f, 0),
            new Vector3(0, 0, 0),
            new Vector3(3.0f, 0, 0),
            new Vector3(3.0f, -0.3f, 0),

            new Vector2(0, 0),
            new Vector2(0, 1),
            new Vector2(1, 1),
            new Vector2(1, 0),

            "Platform", "Platform");
    }

    public void bottomBuild()
    {
        zone.Build(new Vector3(0, -0.3f, 0),
            new Vector3(3.0f, -0.3f, 0),
            new Vector3(3.0f, 0, 0),
            new Vector3(0, 0, 0),

            new Vector2(1, 0),
            new Vector2(0, 0),
            new Vector2(0, 1),
            new Vector2(1, 1),

            "Platform", "Platform");
    }

	// Use this for initialization
	void Start ()
    {
        float x = currentPageProperties.left_limit;
        float y = currentPageProperties.floor_height - transform.position.y;

        transform.Translate(new Vector3(x, y, 0f));
	}
	
	// Update is called once per frame
	void Update ()
    {
	
	}
}
